﻿using System;
using System.Collections.Generic;
using SmartLibrary.Domain.Entities;
using SmartLibrary.Domain.Interfaces.Repository;
using SmartLibrary.Domain.Interfaces.Services;

namespace SmartLibrary.Domain.Services
{
	public class BookService : IBookService
	{
		private readonly IBookRepository _bookRepository;
		private readonly IFileRepository _fileRepository;

		public BookService (IBookRepository bookRepository, IFileRepository fileRepository)
		{
			_bookRepository = bookRepository;
			_fileRepository = fileRepository;
		}

		/// <summary>
		/// Получаем последние добавленные книги
		/// </summary>
		/// <param name="maxBookCount">Максимальное количество выводимых книг</param>
		public List<Book> GetLastBooks (int maxBookCount)
		{
			return _bookRepository.GetBooks(maxBookCount);
		}

		/// <summary>
		/// Получает книгу по её ИД
		/// </summary>
		/// <param name="bookId">ИД книги</param>
		public Book GetBook (Guid bookId)
		{
			return _bookRepository.GetBook(bookId);
		}

		/// <summary>
		/// Добавляет привязку файла к книге
		/// </summary>
		/// <param name="bookFile">Файл</param>
		/// <param name="book">Книга</param>
		public void AddBookFile(BookFile bookFile, Book book)
		{
			bookFile.Book = book;
			_fileRepository.Save(bookFile);
		}

		/// <summary>
		/// Удаляет файл с диска
		/// </summary>
		/// <param name="bookFile">Файл</param>
		public void DeleteBookFile(BookFile bookFile)
		{
			_fileRepository.Delete(bookFile);
		}
	}
}